package com.tm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tm.mapper.StudentMapper;
import com.tm.pojo.entity.Student;
import com.tm.pojo.vo.StudentVo;
import com.tm.service.StudentService;
import com.tm.until.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.Objects;

/**
 * @program: springboot02
 * @description:
 * @author: 小仝
 * @create: 2023-04-12 19:38
 **/

@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public Result findAll(Integer current, Integer pageSize, StudentVo studentVo) {
        // 分页对象
        IPage<Student> page = new Page<>(current,pageSize);
        //条件对象
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(studentVo.getName())){
            wrapper.like("name",studentVo.getName());
        }

        IPage<Student> all = studentMapper.findAll(page, wrapper);// 分页条件查询

        return new Result(200, "查询成功", all);
    }
}
